From da9f725fdcaf2a841377a00e454a21358e3400aa Mon Sep 17 00:00:00 2001 From: oliskoli Date: Thu, 23 Nov 2006 00:49:54 +0000 Subject: [PATCH] Add test for va_copy presents. Break build if not available. --- defs.h | 12 ++++++++++++ util.c | 9 ++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/defs.h b/defs.h index 3c2d5ad93..daa85fef4 100644 --- a/defs.h +++ b/defs.h @@ -86,6 +86,18 @@ # define _CRT_SECURE_NO_DEPRECATE 1 #endif +/* va_copy workaround */ + +#ifndef va_copy +# ifdef __va_copy +# define va_copy __va_copy +# else +# error Function 'va_copy' or '__va_copy' is not defined in your environment! +# error Please mail some information about your system +# error (platform,compiler,...) to gpsbabel-code@lists.sourceforge.net +# endif +#endif + /* Pathname separator character */ #if __WIN32__ # define GB_PATHSEP '\\' diff --git a/util.c b/util.c index 9fa021459..34d61e2bf 100644 --- a/util.c +++ b/util.c @@ -301,6 +301,7 @@ xvasprintf(char **strp, const char *fmt, va_list args) char *newbuf; size_t nextsize = 0; int outsize; + va_list tmp; bufsize = 0; for (;;) { @@ -309,7 +310,7 @@ xvasprintf(char **strp, const char *fmt, va_list args) *strp = NULL; return -1; } - bufsize = 1; + bufsize = FIRSTSIZE; } else if ((newbuf = xrealloc(buf, nextsize)) != NULL) { buf = newbuf; bufsize = nextsize; @@ -319,8 +320,10 @@ xvasprintf(char **strp, const char *fmt, va_list args) return -1; } - outsize = vsnprintf(buf, bufsize, fmt, args); - + va_copy(tmp, args); + outsize = vsnprintf(buf, bufsize, fmt, tmp); + va_end(tmp); + if (outsize == -1) { /* Clear indication that output was truncated, but no * clear indication of how big buffer needs to be, so -- 2.30.2